<template>
  <div>
    <div class="form">
      <div class="search" v-if="isSel">
        <el-input placeholder="企业名称" v-model="companyName" class="search_info">
          <i slot="prefix" class="el-input__icon el-icon-search"></i>
        </el-input>
        <el-select v-model="areaCode" placeholder="区域" class="search_info2">
          <el-option
            v-for="item in areaList"
            :key="item.areaId"
            :label="item.areaName"
            :value="item.areaId"
          ></el-option>
        </el-select>
        <el-date-picker
          value-format="yyyyMMdd"
          v-model="startTime"
          type="date"
          placeholder="开始时间"
        ></el-date-picker>
        <el-date-picker
          class="mar_left"
          value-format="yyyyMMdd"
          v-model="endTime"
          type="date"
          placeholder="结束时间"
        ></el-date-picker>
        <div class="pos_right_btn">
          <el-button @click="reset()">重置</el-button>
          <el-button type="primary" @click="getList(1)" class="searchBtn">搜索</el-button>
          <el-button type="primary" @click="handleExport()" class="searchBtn">导出</el-button>
        </div>
      </div>
      <div class="search" v-if="!isSel">
        <el-select v-model="areaCodeAll" placeholder="区域" class="search_info2">
          <el-option
            v-for="item in areaList"
            :key="item.areaId"
            :label="item.areaName"
            :value="item.areaId"
          ></el-option>
        </el-select>
        <el-date-picker
          value-format="yyyyMMdd"
          v-model="startTimeAll"
          type="date"
          placeholder="开始时间"
        ></el-date-picker>
        <el-date-picker
          class="mar_left"
          value-format="yyyyMMdd"
          v-model="endTimeAll"
          type="date"
          placeholder="结束时间"
        ></el-date-picker>
        <div class="pos_right_btn">
          <el-button @click="reset()">重置</el-button>
          <el-button type="primary" @click="getTotalList(1)" class="searchBtn">搜索</el-button>
        </div>
      </div>
      <div class="row">
        <div class="tabs pad_right" :class="{'sel': isSel}" @click="selClick(true)">明细</div>
        <div class="tabs" :class="{'sel': !isSel}" @click="selClick(false)">合计</div>
      </div>
      <div v-if="isSel">
        <el-table
          class="listTable"
          ref="multipleTable"
          v-loading="listLoading"
          :data="detailList"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="企业名称">
            <template slot-scope="{row}">
              <span>{{ row.companyName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="所属区县" width="100">
            <template slot-scope="{row}">
              <span>{{ row.areaName }}</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="footer">
          <div></div>
          <el-pagination
            :total="total"
            layout="total, sizes, prev, pager, next"
            :page-size="limit"
            :page-sizes="[10, 20, 50, 100]"
            @size-change="handleSizeChange"
            ref="Pagination"
            :current-page.sync="curPage"
            @current-change="getList($event)"
            class="sortStyle"
          />
        </div>
      </div>
      <div v-if="!isSel">
        <el-table
          class="listTable"
          ref="multipleTable"
          v-loading="listLoadings"
          :data="totalList"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column label="区县">
            <template slot-scope="{row}">
              <span>{{ row.areaName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="企业数量" width="100">
            <template slot-scope="{row}">
              <span>{{ row.companyRegisterNum }}</span>
            </template>
          </el-table-column>
          <el-table-column label="排名" width="100">
            <template slot-scope="{row}">
              <span>{{ row.index }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import {
  detailList,
  totalList,
  areaList,
  outDetail
} from "@/api/system/user";
import { MessageBox } from "element-ui";
export default {
  components: {},
  data() {
    return {
      detailList: [],
      listLoading: false,
      listLoadings: false,
      total: 0,
      limit: 10,
      curPage: 0,
      isSel: true,
      totalList: [],
      startTime: '',
      endTime: '',
      areaCode: '',
      areaList: [],
      areaCodeAll: '',
      startTimeAll: '',
      endTimeAll: '',
      companyName: '',
    };
  },
  created() {

  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.getList(1)
      this.getTotalList()
      this.getArea()
    },
    /** 导出按钮操作 */
    handleExport() {
      let params = {
        startTime: this.startTime,
        endTime: this.endTime,
        areaId: this.areaCode,
        companyName: this.companyName
      }
      this.$confirm("是否确认导出企业注册数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return outDetail(params);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    getArea() {
      areaList().then(res => {
        if (res.code == '200') {
          this.areaList = res.rows
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },
    //明细
    getList(page) {
      this.listLoading = true
      let params = {
        pageNum: page,
        pageSize: this.limit,
        startTime: this.startTime,
        endTime: this.endTime,
        areaId: this.areaCode,
        companyName: this.companyName
      }
      detailList(params).then(res => {
        this.listLoading = false
        if (res.code == '200') {
          this.detailList = res.rows
          this.total = res.total
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },
    //合计
    getTotalList(page) {
      this.listLoadings = true
      let params = {
        startTime: this.startTimeAll,
        endTime: this.endTimeAll,
        areaId: this.areaCodeAll
      }
      totalList(params).then(res => {
        this.listLoadings = false
        if (res.code == '200') {
          this.totalList = res.rows
        } else {
          this.$message({ message: res.msg, type: "error" });
        }
      });
    },
    handleSizeChange(val) {
      this.limit = val;
      this.getList(1);
    },
    selClick(tab) {
      this.isSel = tab
    },
    reset() {
      this.startTime = ''
      this.endTime = ''
      this.areaCode = ''
      this.startTimeAll = ''
      this.endTimeAll = ''
      this.areaCodeAll = ''
    }
  }
};
</script>
<style scoped>
.form {
  padding-left: 26px;
  padding-right: 24px;
  padding-top: 24px;
  background: #fff;
}
.search {
  display: flex;
  position: relative;
}
.search1 {
  display: flex;
}
.search_info {
  width: 120px;
  height: 40px;
  margin-right: 16px;
}
.search_info1 {
  width: 200px;
  height: 40px;
  margin-right: 16px;
}
.search_info2 {
  width: 140px;
  height: 40px;
  margin-right: 16px;
}
.searchBtn {
  margin-left: 16px;
  height: 36px;
}
.sortStyle {
  height: 19px;
  float: right;
  /* right: 24px; */
  margin-top: 20px;
  margin-bottom: 30px;
}
.pos_right_btn {
  position: absolute;
  right: 0;
}
.opt_font {
  cursor: pointer;
  color: #2e82ff;
}
.detail_title {
  font-size: 16px;
  font-weight: 400;
  color: #212121;
  line-height: 22px;
}
.detail_title span {
  padding-left: 4px;
  background: #1e88e5;
  margin-right: 12px;
}
.row {
  display: flex;
  /* padding-bottom: 12px; */
}
.detail_info {
  padding-top: 16px;
}
.info_left {
  display: flex;
}
.info_right {
  display: flex;
  /* padding-left: 202px; */
}
.info_left_title {
  font-size: 14px;
  font-weight: 400;
  color: #616161;
  line-height: 20px;
  width: 256px;
  /* margin-right: 16px; */
  text-align: center;
  min-height: 47px;
  background: #f5f7fa;
  box-shadow: inset 0 -1px 0 0 #dcdfe6;
}
.info_left_title .font {
  position: relative;
  top: 14px;
}
.info_left_content {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 256px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  /* position: relative;
    top: 10px; */
}
.info_left_contents {
  font-size: 14px;
  font-weight: 400;
  color: #212121;
  line-height: 20px;
  width: 769px;
  /* border: 1px solid #DCDFE6; */
  box-shadow: inset -1px -1px 0 0 #dcdfe6;
  text-align: left;
}
.pos_top {
  padding-top: 12px;
}
.top_more {
  margin-top: 8px;
}
.detailTable {
  margin-top: 16px;
}
.opt_font {
  color: #1e88e5;
  cursor: pointer;
}
.page_pos {
  text-align: right;
  padding-top: 10px;
}
.backBtn {
  text-align: center;
  margin-top: 10px;
}
/deep/ .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% -30px);
  /* max-width: ; */
}
/deep/ .el-dialog .el-dialog__body {
  flex: 1;
  height: 600px;
  overflow-y: auto;
  padding-top: 0;
}
.tab {
  display: flex;
  position: absolute;
  right: 55px;
  top: 14px;
}
.tab_border {
  border: 1px solid #409eff;
  color: #409eff;
  padding: 10px 12px;
  font-size: 14px;
  margin-right: 16px;
}
.change {
  border: 1px solid #f56c6c;
  color: #f56c6c;
}
.listTable {
  margin-top: 17px;
}
/deep/ .search_info .el-input__inner {
  width: 120px;
}
/deep/ .search_info1 .el-input__inner {
  width: 200px;
}
/deep/ .search_info2 .el-input__inner {
  width: 140px;
}
.date_picker /deep/ .el-input__inner {
  width: 240px;
}
.opt_table {
  display: flex;
  justify-content: space-around;
}
.footer {
  display: flex;
  justify-content: space-between;
}
.footer_btn {
  position: relative;
  top: 20px;
}
.opt_disable {
  color: #909399;
}
.tabs {
  padding-bottom: 10px;
  cursor: pointer;
}
.pad_right {
  margin-right: 10px;
}
.sel {
  border-bottom: #1e88e5 solid 2px;
}
.mar_left {
  margin-left:20px;
}
</style>
